package lion.json.handlers;

import java.io.IOException;
import java.io.Writer;
import java.lang.reflect.Array;

import lion.json.IJsonHandler;
import lion.json.Json;

/**
 * @author lion
 * @mail hl_0074@sina.com
 * @date 2011-9-27
 *
 */
public class ArrayHandler implements IJsonHandler {

	@Override
	public void handle(Object o, Writer writer) throws IOException {

		writer.write("[");
		for (int i = 0; i < Array.getLength(o); i++) {
			if (i > 0) {
				writer.write(",");
			}
			writer.write(Json.toJson(Array.get(o, i)));
		}
		writer.write("]");
	}
}
